var wxRequest = require('../../utils/wxRequest')
var Common = require('../../utils/common');
const app = getApp();
Page({
  goto:app.goto,
	setdata:app.setdata,
  /**
   * 页面的初始数据
   */
  data: {
		sign:"",
    info:{},
    userInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.init(this);

  },

  sign: function () {

    app.api.client_user_checkIn({
      token: wx.getStorageSync('token'),
    }, (res) => {
      this.getRequestData();
      if (res.status == 1){
        this.setData({
          sign: 1,
        })

      }else{
        app.toast(res.msg);
      }
    })    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.api.client_community_getAllBindRoom({
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity"),
      showCancel:false,
    }, (res) => {
      if (res.data.mrRoom == undefined) {
        wx.showModal({
          title: '提示',
          content: '当前小区暂未绑定房屋，请立即绑定',
          showCancel:false,
          success(res) {
            wx.navigateTo({
              url: '../house_me/house_me'
            })
            
          }
        })
      }

    })

    app.init(this);
    this.getRequestData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  getRequestData: function (cb){
    var _that = this;
    var url = app.globalData.domain + "/client/user/getUserCenter";
    var parm = {
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity")
    }
    wxRequest.postRequest(url, parm).then(res => {
      console.log("个人中心=>", res);
      _that.setData({
        info: res.data
      });

    }, error => {
      Common.showToast(error);
    }).then(res => {
      var userInfoUrl = app.globalData.domain + "/client/user/getWxInfo";
      var parm = {
        token: wx.getStorageSync("token")
      }
      wxRequest.postRequest(userInfoUrl, parm).then(res => {
        console.log("用户信息=>", res);
        _that.setData({
          userInfo: res.data
        });

      }, error => {
        Common.showToast(error);
      });
    }).then(res => {
        typeof cb == "function" && cb();
    });;
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // 显示顶部刷新图标
    wx.showNavigationBarLoading();
    this.getRequestData(function () {
      // 隐藏导航栏加载框
      wx.hideNavigationBarLoading();
      // 停止下拉动作
      wx.stopPullDownRefresh();
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  redirectToBillHomePage:function(){
    if (wx.getStorageSync("idCommunity")){
        wx.navigateTo({
          url: '/pages/bill_homepage/bill_homepage'
        })
      }else{
        Common.showToast("请选择所在小区");
      }
  },
  redirectToHouse: function () {
    if (wx.getStorageSync("idCommunity")) {
      wx.navigateTo({
        url: '/pages/house_me/house_me'
      })
    } else {
      Common.showToast("请选择所在小区");
    }
  },
  redirectToCars: function () {
    if (wx.getStorageSync("idCommunity")) {
      wx.navigateTo({
        url: '/pages/car_me/car_me'
      })
    } else {
      Common.showToast("请选择所在小区");
    } 
  },
  redirectToRepair: function () {
    if (wx.getStorageSync("idCommunity")) {
      wx.navigateTo({
        url: '/pages/family_repair_list/family_repair_list'
      })
    } else {
      Common.showToast("请选择所在小区");
    }
  },
  redirectToNotice: function () {
    if (wx.getStorageSync("idCommunity")) {
      wx.navigateTo({
        url: '/pages/notice/notice'
      })
    } else {
      Common.showToast("请选择所在小区");
    }
  },


  client_user_checkIn: function() {


    
  },

  none: function () {
    app.toast('海南城市暂未开放此功能');
  },

  none1: function () {
    app.toast('该小区暂未开放此版块，敬请期待');
  },


  navigateToMiniProgram: function (e) {
    wx.navigateToMiniProgram({
      appId: 'wxb7d56a86bfb85f0c',
      path: 'pages/index/index',
      extraData: {
        foo: 'bar'
      },
      // envVersion: 'develop',
      success(res) {

      }
    })
  },


  
})